package com.greendragon.service.backend.impl; 

import java.util.List;

import com.greendragon.persistence.dao.ICommentDao;
import com.greendragon.persistence.dao.IProductDao;
import com.greendragon.persistence.domain.Product;
import com.greendragon.persistence.domain.ProductComment;
import com.greendragon.persistence.enmu.FetchOrderType;
import com.greendragon.persistence.enmu.LockType;
import com.greendragon.persistence.enmu.VerifyType;
import com.greendragon.service.backend.IProductBackendService;

/** 
 * @author wulibin, exceptsky@gmail.com, 2011-11-7 下午09:51:16
 * 
 */
public class ProductBackendService extends BaseBackendService<Product> implements IProductBackendService{
	private IProductDao productDao;
	private ICommentDao<ProductComment> commentDao;

	@Override
	public void addComment(long pid, ProductComment comment) {
		comment.setProduct(get(pid));
		commentDao.add(comment);
	}

	@Override
	public long getCommentCount(long pid) {
		return commentDao.getCountOfObj(pid, LockType.UNLOCK, VerifyType.VERIFY);
	}

	@Override
	public List<ProductComment> getComments(long pid, int page) {
		return commentDao.getOfObj(pid, pageLength*page, pageLength, LockType.UNLOCK, VerifyType.VERIFY, FetchOrderType.CREATE_DESC);
	}
	
	public void setProductDao(IProductDao productDao) {
		this.productDao = productDao;
		setDao(this.productDao);
	}
	

	public void setCommentDao(ICommentDao<ProductComment> commentDao) {
		this.commentDao = commentDao;
	}

}
 